package com.amigo.online.provider.sync.convert.impl;

import org.apache.solr.common.SolrInputDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.provider.common.entity.UserMysqlInfo;
import com.amigo.online.provider.sync.abs.BasicSolrDataProjectProperties;
import com.amigo.online.provider.sync.convert.ConvertJsonObjectService;

/**
 * <code>SolrUserConvertServiceImpl.java</code>
 * <p>功能:
 *
 * <p>Copyright 南京阿觅谷 2018 All right reserved.
 *
 * @author zhaox 时间 2018年9月4日 上午9:45:08
 * @version 1.0
 * </br>最后修改人 无
 */
@Service("solrUserConvertServiceImpl")
public class SolrUserConvertServiceImpl implements ConvertJsonObjectService<SolrInputDocument, JSONObject, UserMysqlInfo> {

    @Autowired
    BasicSolrDataProjectProperties basicSolrDataProjectProperties;

    @Override
    public SolrInputDocument convert(JSONObject source) {
        SolrInputDocument document = new SolrInputDocument();
        for (String temp : basicSolrDataProjectProperties.getUserUpdateList()) {
            document.addField(temp, source.get(temp));
        }
	/*	document.addField("birthday", source.getLong("birthday")); //生日
		document.addField("mobilephone", source.getString("mobilephone"));//手机号
		document.addField("nickname", source.getString("nickname"));//昵称
		document.addField("sign", source.getString("sign"));//签名
		document.addField("id", source.getLong("id").toString());//id
		document.addField("avatar", source.getString("avatar"));//头像
		document.addField("account", source.getString("account"));//amigo账号
*/		
		/*document.addField("sex", source.getString("sex"));//性别
		document.addField("email", source.getString("email"));//emai		
		document.addField("country", source.getIntValue("country"));//国家
		document.addField("city", source.getIntValue("city"));//城市		
		document.addField("background", source.getString("background"));//背景图片
*/

        return document;
    }

    @Override
    public SolrInputDocument convertBeanToObject(UserMysqlInfo source) {
        SolrInputDocument document = new SolrInputDocument();
        document.addField("birthday", source.getBirthday()); //生日
        document.addField("mobilephone", source.getMobilePhone());//手机号
        document.addField("nickname", source.getNickname());//昵称
        document.addField("sign", source.getSign());//签名
        document.addField("id", source.getId());//id
        document.addField("avatar", source.getAvatar());//头像
        document.addField("account", source.getAccount());//amigo账号
        document.addField("sex", source.getSex());
        return document;
    }

}
